package cn.h8k.hj212.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * HJ212协议数据部分实体类
 * 包含协议的所有数据字段和CP数据组
 */
public class Hj212Data {
    
    /**
     * 请求编号，时间戳
     */
    private String qn;
    
    /**
     * 系统编号，协议版本
     */
    private String st;
    
    /**
     * 命令编号
     */
    private String cn;
    
    /**
     * 访问密码
     */
    private String pw;
    
    /**
     * 设备唯一标识
     */
    private String mn;
    
    /**
     * 数据标志
     */
    private String flag;
    
    /**
     * CP数据组列表
     */
    private List<Hj212CpGroup> cpGroups;
    
    /**
     * 默认构造函数
     */
    public Hj212Data() {
        this.cpGroups = new ArrayList<>();
    }
    
    /**
     * 构造函数
     * @param qn 请求编号
     * @param st 系统编号
     * @param cn 命令编号
     * @param pw 访问密码
     * @param mn 设备唯一标识
     * @param flag 数据标志
     */
    public Hj212Data(String qn, String st, String cn, String pw, String mn, String flag) {
        this.qn = qn;
        this.st = st;
        this.cn = cn;
        this.pw = pw;
        this.mn = mn;
        this.flag = flag;
        this.cpGroups = new ArrayList<>();
    }
    
    public String getQn() {
        return qn;
    }
    
    public void setQn(String qn) {
        this.qn = qn;
    }
    
    public String getSt() {
        return st;
    }
    
    public void setSt(String st) {
        this.st = st;
    }
    
    public String getCn() {
        return cn;
    }
    
    public void setCn(String cn) {
        this.cn = cn;
    }
    
    public String getPw() {
        return pw;
    }
    
    public void setPw(String pw) {
        this.pw = pw;
    }
    
    public String getMn() {
        return mn;
    }
    
    public void setMn(String mn) {
        this.mn = mn;
    }
    
    public String getFlag() {
        return flag;
    }
    
    public void setFlag(String flag) {
        this.flag = flag;
    }
    
    public List<Hj212CpGroup> getCpGroups() {
        return cpGroups;
    }
    
    public void setCpGroups(List<Hj212CpGroup> cpGroups) {
        this.cpGroups = cpGroups;
    }
    
    /**
     * 添加CP数据组
     * @param cpGroup CP数据组
     */
    public void addCpGroup(Hj212CpGroup cpGroup) {
        if (this.cpGroups == null) {
            this.cpGroups = new ArrayList<>();
        }
        this.cpGroups.add(cpGroup);
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Hj212Data that = (Hj212Data) o;
        return Objects.equals(qn, that.qn) &&
               Objects.equals(st, that.st) &&
               Objects.equals(cn, that.cn) &&
               Objects.equals(pw, that.pw) &&
               Objects.equals(mn, that.mn) &&
               Objects.equals(flag, that.flag) &&
               Objects.equals(cpGroups, that.cpGroups);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(qn, st, cn, pw, mn, flag, cpGroups);
    }
    
    @Override
    public String toString() {
        return "Hj212Data{" +
                "qn='" + qn + '\'' +
                ", st='" + st + '\'' +
                ", cn='" + cn + '\'' +
                ", pw='" + pw + '\'' +
                ", mn='" + mn + '\'' +
                ", flag='" + flag + '\'' +
                ", cpGroups=" + cpGroups +
                '}';
    }
} 